package blackhouse_servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import blackhouse_entity.subject;
import blackhouse_server.subject_server;

import com.alibaba.fastjson.JSON;

@WebServlet("/subject")
public class subject_servlet extends HttpServlet
{
	subject_server	SS	= new subject_server();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		// TODO Auto-generated method stub
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		String seek1 = req.getParameter("sea1");
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String code = req.getParameter("code");
		PrintWriter print = resp.getWriter();
		String ID = (String) req.getSession().getAttribute("user");
		List<subject> list = null;
		String json = null;
		try
		{
			if (code.equals("0"))
			{
				list = SS.stu_subject_server(seek1, ID);
				json = JSON.toJSONString(list);
				print.write(json);
			} else if (code.equals("10"))
			{
				list = SS.cheek_subject();
				json = JSON.toJSONString(list);
				print.write(json);
			} else
			{
				list = SS.subject_server(seek1);
				json = JSON.toJSONString(list);
				print.write(json);
			}
		} catch (SQLException e)
		{
			e.printStackTrace();
		}

	}

	private boolean code(boolean equals)
	{
		// TODO Auto-generated method stub
		return false;
	}
}
